/*
 * 'tty.h' defines some structures used by tty_io.c and some defines.
 *
 * NOTE! Don't touch this without checking that nothing in rs_io.s or
 * con_io.s breaks. Some constants are hardwired into the system (mainly
 * offsets into 'tty_queue'
 */
#ifndef _TTY_H
#define _TTY_H

#define MAX_CONSOLES    8
#define NR_SERIALS      2
#define NR_PTYS         4

extern int NR_CONSOLES;

#include <termios.h>

#define TTY_BUF_SIZE 1024
struct tty_queue {
	unsigned long data; /* 数据统计值，如果是串口终端则是串口的端口地址 */
	unsigned long head; /* 指向环形缓冲区buf的头部 */
	unsigned long tail; /* 指向环形缓冲区buf的尾部 */
	struct task_struct * proc_list;
	char buf[TTY_BUF_SIZE];
};

/* tty会话：包含多个终端 */
struct tty_struct {
	struct termios termios;
	int pgrp;                   /* 进程组 */
	int session;                /* 会话ID */
	int stopped;                /* 停止标志 */
	void (*write)(struct tty_struct * tty); /* tty 会话的写操作 */
	struct tty_queue *read_q;   /* tty 读队列 */
	struct tty_queue *write_q;  /* tty 写队列 */
	struct tty_queue *secondary;/* tty 规范队列 */
};

/**
    intr=^C		quit=^|		erase=del	kill=^U
	eof=^D		vtime=\0	vmin=\1		sxtc=\0
	start=^Q	stop=^S		susp=^Z		eol=\0
	reprint=^R	discard=^U	werase=^W	lnext=^V
	eol2=\0
*/
#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"

void rs_init(void);
void tty_init(void);
void con_init(void);

void con_write(struct tty_struct * tty);
void rs_write(struct tty_struct * tty);
void mpty_write(struct tty_struct * tty);
void spty_write(struct tty_struct * tty);

#endif /* _TTY_H */